package com.report.reportserver.service.impl;

import com.report.reportserver.mapper.StudentMapper;
import com.report.reportserver.model.Student;
import com.report.reportserver.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.relational.core.sql.In;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @ ClassName: StudentServiceImpl
 * @ Description：查询学生对象
 * @ Modified By：
 * @ Version:
 * @ Author     ：LiYing
 * @ Date       ：Created in 11:20 2022/3/29
 */
@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    StudentMapper studentMapper;

    @Override
    public Student queryStudentById(Integer id) {
        return studentMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Student> queryStudentByName(String name) {
        List<Student> list = studentMapper.selectByName(name);
        return list;
    }

    @Override
    /*
     * 查询学号在number1和number2里的学生
     * @param number1
     * @param number2
     * @return java.util.List<com.report.reportserver.model.Student>
     * @author LiYing
     * @creed: Talk is cheap,show me the code
     * @date 2022/4/30 10:11
     */
    public List<Student> queryStudentByNumber(int number1, int number2) {
        List<Integer> ids = studentMapper.selectAllId();
        List<Student> students = new ArrayList<>();
        for (Integer id : ids) {
            Student student = studentMapper.selectByPrimaryKey(id);
            Integer number = Integer.parseInt(student.getNumber());
            if (number >= number1 && number <= number2) {
                students.add(student);
            }
        }
        return students;
    }

    @Override
    public List<Integer> queryStudentAllId() {
        return studentMapper.selectAllId();
    }

    @Override
    public Student queryStudentByNumber(String number) {
        return studentMapper.selectByNumber(number);
    }

    @Override
    public void insertStudent(Student record) {
        studentMapper.insert(record);
    }
}
